package pwd

import (
	"github.com/sirupsen/logrus"
	"golang.org/x/crypto/bcrypt"
)

// 加密
func GenerateHash(origin string) (string, error) {
	hasValue, err := bcrypt.GenerateFromPassword([]byte(origin), bcrypt.DefaultCost)
	if err != nil {
		logrus.Error("加密失败")
		return "", err
	}
	return string(hasValue), nil
}

// 解密
func LiftedHash(hashValue string, origin string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashValue), []byte(origin))
	if err != nil {
		logrus.Warning("密码错误")
		return false
	}
	return true
}
